{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "import k3d\n",
    "import numpy as np\n",
    "from numpy import sin,cos,pi\n",
    "\n",
    "plot = k3d.plot()\n",
    "\n",
    "T = 1.618033988749895\n",
    "r = 4.77\n",
    "zmin,zmax = -r,r\n",
    "xmin,xmax = -r,r\n",
    "ymin,ymax = -r,r\n",
    "Nx,Ny,Nz = 77,77,77\n",
    "\n",
    "x = np.linspace(xmin,xmax,Nx)\n",
    "y = np.linspace(ymin,ymax,Ny)\n",
    "z = np.linspace(zmin,zmax,Nz)\n",
    "x,y,z = np.meshgrid(x,y,z,indexing='ij')\n",
    "p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)).astype(np.float32)\n",
    "a = (sin(x + T*y) + sin(x - T*y) + sin(y + T*z) + cos(y - T*z) + sin(z - T*x) + cos(z + T*x)).astype(np.float32)\n",
    "iso = k3d.marching_cubes(p, attribute=a, level=0.0)\n",
    "plot += iso\n",
    "plot.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iso.attribute = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iso.attribute = a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iso.flat_shading = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iso.level = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
